package sun.nan.test.matlab;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import matlabcontrol.MatlabConnectionException;
import matlabcontrol.MatlabInvocationException;
import matlabcontrol.MatlabProxy;
import matlabcontrol.MatlabProxyFactory;

public class RunMFile {
	public static void main(String[] args) throws MatlabConnectionException,
			MatlabInvocationException, IOException {

		// Create a proxy, which we will use to control MATLAB
		MatlabProxyFactory factory = new MatlabProxyFactory();
		MatlabProxy proxy = factory.getProxy();

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				new FileInputStream(new File(
						"C:/Users/linan/Desktop/mat/test.m")), "GBK"));
		String oneLine = null;
		while ((oneLine = reader.readLine()) != null) {
			proxy.eval(oneLine);
		}
		reader.close();
		// Disconnect the proxy from MATLAB
		proxy.disconnect();

	}
}
